#include "stdafx.h"
#include "Controller.h"

WMReaderController::WMReaderController(WMReaderModel *model, WMReaderView* view)
{
    m_Model.reset(model);
    m_View.reset(view); 
    ConnectSignalsWithSlots();
}

void WMReaderController::ConnectSignalsWithSlots()
{
    connect(m_View.get(), SIGNAL(RequestConnectToDevice()),
                                m_Model.get(), SLOT(ConnectToDevice()));
    connect(m_Model.get(), SIGNAL(DeviceConnected()),
                                m_View.get(), SLOT(DeviceConnected()));

    connect(m_View.get(), SIGNAL(RequestDisconnectFromDevice()),
                                m_Model.get(), SLOT(DisconnectFromDevice()));
    connect(m_Model.get(), SIGNAL(DeviceDisconnected()),
                                m_View.get(), SLOT(DeviceDisconnected()));

    connect(m_View.get(), SIGNAL(RequestFileSystem(QTreeWidgetItem*)),
                                m_Model.get(), SLOT(RetrieveFileSystem(QTreeWidgetItem*)));  
    connect(m_Model.get(), SIGNAL(FileSystemRetrieved(QTreeWidgetItem*, std::vector<CE_FIND_DATA>*)),
                                m_View.get(), SLOT(FileSystemRetrieved(QTreeWidgetItem*, std::vector <CE_FIND_DATA>*)));

    connect(m_View.get(), SIGNAL(RequestRegistryKeysList(QTreeWidgetItem*)),
                                m_Model.get(), SLOT(RetrieveRegistryKeysList(QTreeWidgetItem*)));
    connect(m_Model.get(), SIGNAL(RegistryKeysListRetrieved(QTreeWidgetItem*, std::vector <registry_set::REGKEY>*)),
                                m_View.get(), SLOT(RegistryKeysListRetrieved(QTreeWidgetItem*, std::vector <registry_set::REGKEY>*)));

    connect(m_View.get(), SIGNAL(RequestRegistryKeyValues(QTreeWidgetItem*)),
                                m_Model.get(), SLOT(RetrieveRegistryKeyValues(QTreeWidgetItem*)));
    connect(m_Model.get(), SIGNAL(RegistryKeyValuesRetrieved(std::vector <registry_set::REGKEYVALUE>*)),
                                m_View.get(), SLOT(RegistryKeyValuesRetrieved(std::vector <registry_set::REGKEYVALUE>*)));
    
    connect(m_View.get(), SIGNAL(RequestDeviceInfo()),
                                m_Model.get(), SLOT(RetrieveDeviceInfo()));
    connect(m_Model.get(), SIGNAL(DeviceInfoRetrieved(std::vector <device_info::DEVICEINFO>*)),
                                m_View.get(), SLOT(DeviceInfoRetrieved(std::vector <device_info::DEVICEINFO>*)));

    connect(m_Model.get(), SIGNAL(RequestShowErrorMessage(const QString&)),
                                m_View.get(), SLOT(ShowErrorMessage(const QString&)));
}
